﻿Public Class Khibra
    Public Id As Integer
    Public Num As Integer
    Public Date_decision As Date
    Public Remarque As String

    'Les constructeur ----------------------

    Sub New(ByVal Id As Integer, ByVal Num As Integer, ByVal Date_decisin As Date, ByVal Remarque As String)
        Me.Id = Id
        Me.Num = Num
        Me.Date_decision = Date_decisin

        Me.Remarque = Remarque
    End Sub

    Sub New()

    End Sub

    'les listes ------------------------------

    Public List_depences_khibra As New ArrayList
    Public List_khabir As New ArrayList

    'les fonctions ------------------------

    Public Sub remplir_list_khabir()
        Me.List_khabir.Clear()
        Dim cmd As New SqlClient.SqlCommand("select * from khibra_khabir where id_khibra=" & Me.Id, Partager.con)
        Partager.Open()
        Partager.dr = cmd.ExecuteReader
        While Partager.dr.Read
            Dim khab As New Khibra_khabir(Partager.dr("Id_Khabir"), Partager.dr("Id_Khibra"), Partager.dr("nomme"))
            Me.List_khabir.Add(khab)
        End While
        Partager.Close()
    End Sub

    Public Sub suprimmer_khabir(ByVal khab As Khibra_khabir)

        Dim cmd As New SqlClient.SqlCommand("delete from khibra_khabir where id_khabir=" & khab.Id_Khabir & " and Id_Khibra=" & khab.Id_Khibra, Partager.con)

        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

        Me.remplir_list_khabir()


    End Sub

    Public Sub Ajouter_khabir(ByVal id As Integer)
        Dim cmd As New SqlClient.SqlCommand("insert into khibra_khabir values(" & id & "," & Me.Id & ",1,GETDATE())", Partager.con)

        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

        Me.remplir_list_khabir()
    End Sub

    Public Sub modifierkhabNomme(ByVal ad As Khibra_khabir)
        Dim str As String = "0"
        If ad.nomme Then
            str = "1"
        End If
        Dim cmd As New SqlClient.SqlCommand("update Khibra_khabir set nomme=" & str _
        & "where Id_Khabir= " & ad.Id_Khabir & "and Id_Khibra=" & ad.Id_Khibra, Partager.con)

        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

        Me.remplir_list_khabir()
    End Sub


    Public Sub remplir_list_depences_khibra()
        Me.List_depences_khibra.Clear()
        Dim cmd As New SqlClient.SqlCommand("select * from Deponses_Khibra where Id_Khibra=" & Me.Id, Partager.con)
        Partager.Open()
        Partager.dr = cmd.ExecuteReader
        While Partager.dr.Read
            Dim khab As New Depenses_khibra(Partager.dr("id"), Partager.dr("Num_Compte"), Partager.dr("Num_Recus"), Partager.dr("Montant"), Partager.dr("type"), Partager.dr("Date_Deponse"), Partager.dr("Remarque"))
            Me.List_depences_khibra.Add(khab)
        End While
        Partager.Close()
    End Sub

    Public Sub suprimmer_depences_khibra(ByVal id As Integer)

        Dim cmd As New SqlClient.SqlCommand("delete from Deponses_Khibra where id=" & id, Partager.con)

        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

        Me.remplir_list_depences_khibra()


    End Sub

    Public Sub Ajouter_depences_khibra(ByVal khib As Depenses_khibra)

        Dim cmd As New SqlClient.SqlCommand("insert into Deponses_Khibra values (@Id_Khibra,@Num_Compte,@Num_Recus,@Montant,@type,@Date_Deponse,@Remarque,GETDATE())", Partager.con)

        cmd.Parameters.Add("@Id_Khibra", SqlDbType.Int).Value = Me.Id
        cmd.Parameters.Add("@Num_Compte", SqlDbType.VarChar).Value = khib.Num_compt
        cmd.Parameters.Add("@Num_Recus", SqlDbType.VarChar).Value = khib.Num_recus
        cmd.Parameters.Add("@Montant", SqlDbType.Float).Value = khib.Montant
        cmd.Parameters.Add("@type", SqlDbType.VarChar).Value = khib.type
        cmd.Parameters.Add("@Date_Deponse", SqlDbType.Date).Value = khib.Date_depence
        cmd.Parameters.Add("@Remarque", SqlDbType.VarChar).Value = khib.Remarque

        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        Me.remplir_list_depences_khibra()
    End Sub

    Public Sub modifier_depences_khibra(ByVal id As Integer, ByVal khib As Depenses_khibra)


        Dim cmd As New SqlClient.SqlCommand("update Deponses_Khibra set Id_Khibra=@Id_Khibra, Num_Compte=@Num_Compte,Num_Recus=@Num_Recus,Montant=@Montant,type=@type,Date_Deponse=@Date_Deponse,Remarque=@Remarque where id=" & id, Partager.con)

        cmd.Parameters.Add("@Id_Khibra", SqlDbType.Int).Value = Me.Id
        cmd.Parameters.Add("@Num_Compte", SqlDbType.VarChar).Value = khib.Num_compt
        cmd.Parameters.Add("@Num_Recus", SqlDbType.VarChar).Value = khib.Num_recus
        cmd.Parameters.Add("@Montant", SqlDbType.Float).Value = khib.Montant
        cmd.Parameters.Add("@type", SqlDbType.VarChar).Value = khib.type
        cmd.Parameters.Add("@Date_Deponse", SqlDbType.Date).Value = khib.Date_depence
        cmd.Parameters.Add("@Remarque", SqlDbType.VarChar).Value = khib.Remarque

        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        Me.remplir_list_depences_khibra()

    End Sub


End Class
